home *** CD-ROM | disk | FTP | other *** search
/ Express Pd: GALORE / Express Pd Galore - The Amiga PD & Shareware CD (1994)(Express Pd)[!][Amiga-CD32-CDTV].iso / productivity / term / termprint.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  19KB  |  880 lines

  1. /*
  2. **    termPrint.c
  3. **
  4. **    Printer control routines
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...):
  13.      *
  14.      *    Output a printf() style message.
  15.      */
  16.  
  17. BYTE
  18. PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...)
  19. {
  20.     va_list    VarArgs;
  21.     LONG    Len;
  22.  
  23.     va_start(VarArgs,String);
  24.     VSPrintf(SharedBuffer,String,VarArgs);
  25.     va_end(VarArgs);
  26.  
  27.     if(ReqWindow)
  28.     {
  29.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  30.         {
  31.             *Error = 0;
  32.  
  33.             return(FALSE);
  34.         }
  35.     }
  36.     else
  37.     {
  38.         if(CheckSignal(SIG_BREAK))
  39.         {
  40.             *Error = 0;
  41.  
  42.             return(FALSE);
  43.         }
  44.     }
  45.  
  46.     Len = strlen(SharedBuffer) + 1;
  47.  
  48.     if(FPrintf(File,"%s\n",SharedBuffer) < Len)
  49.     {
  50.         *Error = IoErr();
  51.  
  52.         return(FALSE);
  53.     }
  54.     else
  55.         return(TRUE);
  56. }
  57.  
  58.     /* PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code):
  59.      *
  60.      *    Print a line header.
  61.      */
  62.  
  63. STATIC BYTE
  64. PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code,BYTE Plain)
  65. {
  66.     STRPTR    String;
  67.     LONG    Len;
  68.  
  69.     String = LocaleString(Code);
  70.     Len = strlen(String);
  71.  
  72.     if(ReqWindow)
  73.     {
  74.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  75.         {
  76.             *Error = 0;
  77.  
  78.             return(FALSE);
  79.         }
  80.     }
  81.     else
  82.     {
  83.         if(CheckSignal(SIG_BREAK))
  84.         {
  85.             *Error = 0;
  86.  
  87.             return(FALSE);
  88.         }
  89.     }
  90.  
  91.     if(!Plain)
  92.     {
  93.         if(FWrite(File,"\33[1m",4,1) < 1)
  94.         {
  95.             *Error = IoErr();
  96.  
  97.             return(FALSE);
  98.         }
  99.     }
  100.  
  101.     if(FWrite(File,String,Len,1) < 1)
  102.     {
  103.         *Error = IoErr();
  104.  
  105.         return(FALSE);
  106.     }
  107.  
  108.     if(!Plain)
  109.     {
  110.         if(FWrite(File,"\33[0m",4,1) < 1)
  111.         {
  112.             *Error = IoErr();
  113.  
  114.             return(FALSE);
  115.         }
  116.     }
  117.  
  118.     return(TRUE);
  119. }
  120.  
  121.     /* PrintFileInformation():
  122.      *
  123.      *    Print information on a file.
  124.      */
  125.  
  126. BYTE
  127. PrintFileInformation(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR Name,ULONG Flags)
  128. {
  129.     BYTE Continue = TRUE;
  130.  
  131.         /* Any special information to print along with the name? */
  132.  
  133.     if(Flags)
  134.     {
  135.         BPTR FileLock;
  136.  
  137.             /* Try to grip the file. */
  138.  
  139.         if(FileLock = Lock(Name,ACCESS_READ))
  140.         {
  141.             struct FileInfoBlock *FileInfo;
  142.  
  143.                 /* Allocate info buffer. */
  144.  
  145.             if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  146.             {
  147.                     /* How does it look like? */
  148.  
  149.                 if(Examine(FileLock,FileInfo))
  150.                 {
  151.                     UBYTE    DummyBuffer[300];
  152.                     STRPTR    Index;
  153.  
  154.                         /* Add the size. */
  155.  
  156.                     if(Flags & PRINT_SIZE)
  157.                         SPrintf(DummyBuffer,"%-25s %7ld",FilePart(Name),FileInfo -> fib_Size);
  158.                     else
  159.                         SPrintf(DummyBuffer,"%-25s",FilePart(Name));
  160.  
  161.                     Index = DummyBuffer;
  162.  
  163.                         /* Find the end of the string. */
  164.  
  165.                     while(*Index)
  166.                         Index++;
  167.  
  168.                         /* Add the protection bits. */
  169.  
  170.                     if(Flags & PRINT_BITS)
  171.                     {
  172.                         STATIC STRPTR    SetBits = "----aps",
  173.                                 ClrBits = "dewr---";
  174.  
  175.                         UBYTE TempString[10];
  176.  
  177.                         WORD i;
  178.  
  179.                         strcpy(TempString," -------");
  180.  
  181.                         for(i = 0 ; i < 7 ; i++)
  182.                         {
  183.                             if(FileInfo -> fib_Protection & (1 << i))
  184.                                 TempString[6 - i + 1] = SetBits[i]; 
  185.                             else
  186.                                 TempString[6 - i + 1] = ClrBits[i]; 
  187.                         }
  188.  
  189.                         strcpy(Index,TempString);
  190.  
  191.                         while(*Index)
  192.                             Index++;
  193.                     }
  194.  
  195.                         /* Add the creation date. */
  196.  
  197.                     if(Flags & PRINT_DATE)
  198.                     {
  199.                         UBYTE        Date[20],
  200.                                 Time[20];
  201.                         struct DateTime    DateTime;
  202.  
  203.                             /* Prepare for date conversion. */
  204.  
  205.                         DateTime . dat_Stamp    = FileInfo -> fib_Date;
  206.                         DateTime . dat_Format    = FORMAT_DOS;
  207.                         DateTime . dat_Flags    = DTF_SUBST;
  208.                         DateTime . dat_StrDay    = NULL;
  209.                         DateTime . dat_StrDate    = Date;
  210.                         DateTime . dat_StrTime    = Time;
  211.  
  212.                             /* Convert the date. */
  213.  
  214.                         if(DateToStr(&DateTime))
  215.                         {
  216.                             SPrintf(Index," %-9s %s",Date,Time);
  217.  
  218.                             while(*Index)
  219.                                 Index++;
  220.                         }
  221.                     }
  222.  
  223.                         /* Add the file comment. */
  224.  
  225.                     if(Flags & PRINT_COMMENT)
  226.                         SPrintf(Index,"\n: %s",FileInfo -> fib_Comment);
  227.  
  228.                     Continue = PrintText(File,ReqWindow,Error,"%s\n",DummyBuffer);
  229.                 }
  230.                 else
  231.                     Continue = FALSE;
  232.  
  233.                 FreeDosObject(DOS_FIB,FileInfo);
  234.             }
  235.             else
  236.                 Continue = FALSE;
  237.  
  238.             UnLock(FileLock);
  239.         }
  240.         else
  241.             Continue = FALSE;
  242.     }
  243.     else
  244.         Continue = PrintText(File,ReqWindow,Error,"%s\n",Name);
  245.  
  246.     return(Continue);
  247. }
  248.  
  249.     /* PrintEntry(BPTR File,struct Window *ReqWindow,LONG *Error,struct PhoneEntry *Entry):
  250.      *
  251.      *    Print information on the contents of a phonebook entry.
  252.      */
  253.  
  254. BYTE
  255. PrintEntry(BPTR File,struct Window *ReqWindow,BYTE Plain,LONG *Error,struct PhoneEntry *Entry,ULONG Flags)
  256. {
  257.     if(Plain)
  258.     {
  259.         if(!PrintText(File,ReqWindow,Error,"\n\"%s\" (%s)",Entry -> Header -> Name,Entry -> Header -> Number))
  260.             return(FALSE);
  261.     }
  262.     else
  263.     {
  264.         if(!PrintText(File,ReqWindow,Error,"\n\33[4m\"%s\" (%s)\33[0m",Entry -> Header -> Name,Entry -> Header -> Number))
  265.             return(FALSE);
  266.     }
  267.  
  268.     if(Flags & PRINT_COMMENT)
  269.     {
  270.         if(Entry -> Header -> Comment[0])
  271.         {
  272.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COMMENT_TXT,Plain))
  273.                 return(FALSE);
  274.  
  275.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> Comment))
  276.                 return(FALSE);
  277.         }
  278.     }
  279.  
  280.     if(Flags & PRINT_USERNAME)
  281.     {
  282.         if(Entry -> Header -> UserName[0])
  283.         {
  284.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_USER_NAME_TXT,Plain))
  285.                 return(FALSE);
  286.  
  287.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> UserName))
  288.                 return(FALSE);
  289.         }
  290.     }
  291.  
  292.     if((Flags & PRINT_SERIAL) && Entry -> Config -> SerialConfig)
  293.     {
  294.         STATIC UBYTE Parities[] =
  295.         {
  296.             'N','E','O','M','S'
  297.         };
  298.  
  299.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_BAUD_RATE_TXT,Plain))
  300.             return(FALSE);
  301.  
  302.         if(LocaleBase)
  303.         {
  304.             if(!PrintText(File,ReqWindow,Error,"%lD",Entry -> Config -> SerialConfig -> BaudRate))
  305.                 return(FALSE);
  306.         }
  307.         else
  308.         {
  309.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> SerialConfig -> BaudRate))
  310.                 return(FALSE);
  311.         }
  312.  
  313.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_PARAMETERS_TXT,Plain))
  314.             return(FALSE);
  315.  
  316.         if(!PrintText(File,ReqWindow,Error,"%ld-%lc-%ld",Entry -> Config -> SerialConfig -> BitsPerChar,Parities[Entry -> Config -> SerialConfig -> Parity],Entry -> Config -> SerialConfig -> StopBits))
  317.             return(FALSE);
  318.  
  319.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANDSHAKING_TXT,Plain))
  320.             return(FALSE);
  321.  
  322.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_HANDSHAKING_NONE_TXT + Entry -> Config -> SerialConfig -> HandshakingProtocol)))
  323.             return(FALSE);
  324.  
  325.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DUPLEX_TXT,Plain))
  326.             return(FALSE);
  327.  
  328.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_DUPLEX_FULL_TXT + Entry -> Config -> SerialConfig -> Duplex)))
  329.             return(FALSE);
  330.  
  331.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_STRIP_BIT_TXT,Plain))
  332.             return(FALSE);
  333.  
  334.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> StripBit8)))
  335.             return(FALSE);
  336.  
  337.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FLOW_CONTROL_TXT,Plain))
  338.             return(FALSE);
  339.  
  340.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> xONxOFF)))
  341.             return(FALSE);
  342.  
  343.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_SERIAL_DRIVER_TXT,Plain))
  344.             return(FALSE);
  345.  
  346.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_NAME_UNIT_TEMPLATE_TXT),Entry -> Config -> SerialConfig -> SerialDevice, + Entry -> Config -> SerialConfig -> UnitNumber))
  347.             return(FALSE);
  348.     }
  349.  
  350.     if((Flags & PRINT_MODEM) && Entry -> Config -> ModemConfig)
  351.     {
  352.         if(Entry -> Config -> ModemConfig -> ModemInit[0])
  353.         {
  354.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_INIT_TXT,Plain))
  355.                 return(FALSE);
  356.  
  357.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemInit))
  358.                 return(FALSE);
  359.         }
  360.  
  361.         if(Entry -> Config -> ModemConfig -> ModemExit[0])
  362.         {
  363.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_EXIT_TXT,Plain))
  364.                 return(FALSE);
  365.  
  366.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemExit))
  367.                 return(FALSE);
  368.         }
  369.  
  370.         if(Entry -> Config -> ModemConfig -> ModemHangup[0])
  371.         {
  372.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANG_UP_TXT,Plain))
  373.                 return(FALSE);
  374.  
  375.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemHangup))
  376.                 return(FALSE);
  377.         }
  378.  
  379.         if(Entry -> Config -> ModemConfig -> DialPrefix[0])
  380.         {
  381.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_PREFIX_TXT,Plain))
  382.                 return(FALSE);
  383.  
  384.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialPrefix))
  385.                 return(FALSE);
  386.         }
  387.  
  388.         if(Entry -> Config -> ModemConfig -> DialSuffix[0])
  389.         {
  390.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_SUFFIX_TXT,Plain))
  391.                 return(FALSE);
  392.  
  393.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialSuffix))
  394.                 return(FALSE);
  395.         }
  396.  
  397.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_REDIAL_DELAY_TXT,Plain))
  398.             return(FALSE);
  399.  
  400.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> RedialDelay / 6,(Entry -> Config -> ModemConfig -> RedialDelay % 6) * 10))
  401.             return(FALSE);
  402.  
  403.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_TIMEOUT_TXT,Plain))
  404.             return(FALSE);
  405.  
  406.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> DialTimeout / 60,Entry -> Config -> ModemConfig -> DialTimeout % 60))
  407.             return(FALSE);
  408.  
  409.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_AUTO_BAUD_TXT,Plain))
  410.             return(FALSE);
  411.  
  412.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> ConnectAutoBaud)))
  413.             return(FALSE);
  414.  
  415.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DROP_DTR_TXT,Plain))
  416.             return(FALSE);
  417.  
  418.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> DropDTR)))
  419.             return(FALSE);
  420.     }
  421.  
  422.     if((Flags & PRINT_SCREEN) && Entry -> Config -> ScreenConfig)
  423.     {
  424.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DISPLAY_MODE_TXT,Plain))
  425.             return(FALSE);
  426.  
  427.         if(!PrintText(File,ReqWindow,Error,GetModeName(Entry -> Config -> ScreenConfig -> DisplayMode)))
  428.             return(FALSE);
  429.  
  430.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COLOUR_MODE_TXT,Plain))
  431.             return(FALSE);
  432.  
  433.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SCREENPANEL_COLOUR_AMIGA_TXT + Entry -> Config -> ScreenConfig -> ColourMode)))
  434.             return(FALSE);
  435.     }
  436.  
  437.     if((Flags & PRINT_TERMINAL) && Entry -> Config -> TerminalConfig)
  438.     {
  439.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TERMINAL_EMULATION_TXT,Plain))
  440.             return(FALSE);
  441.  
  442.         if(Entry -> Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  443.         {
  444.             if(!PrintText(File,ReqWindow,Error,"%s, \"%s\"",LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode),Entry -> Config -> TerminalConfig -> EmulationMode))
  445.                 return(FALSE);
  446.         }
  447.         else
  448.         {
  449.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode)))
  450.                 return(FALSE);
  451.         }
  452.  
  453.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FONT_TXT,Plain))
  454.             return(FALSE);
  455.  
  456.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_FONT_STANDARD_TXT + Entry -> Config -> TerminalConfig -> FontMode)))
  457.             return(FALSE);
  458.  
  459.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_COLUMNS_TXT,Plain))
  460.             return(FALSE);
  461.  
  462.         if(Entry -> Config -> TerminalConfig -> NumColumns < 20)
  463.         {
  464.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  465.                 return(FALSE);
  466.         }
  467.         else
  468.         {
  469.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumColumns))
  470.                 return(FALSE);
  471.         }
  472.  
  473.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_LINES_TXT,Plain))
  474.             return(FALSE);
  475.  
  476.         if(Entry -> Config -> TerminalConfig -> NumLines < 20)
  477.         {
  478.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  479.                 return(FALSE);
  480.         }
  481.         else
  482.         {
  483.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumLines))
  484.                 return(FALSE);
  485.         }
  486.  
  487.         if(Entry -> Config -> TerminalConfig -> KeyMapFileName[0])
  488.         {
  489.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_KEYMAP_FILE_TXT,Plain))
  490.                 return(FALSE);
  491.  
  492.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> TerminalConfig -> KeyMapFileName))
  493.                 return(FALSE);
  494.         }
  495.     }
  496.  
  497.     return(TRUE);
  498. }
  499.  
  500.     /* PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error):
  501.      *
  502.      *    Print the contents of the screen, requires the raster
  503.      *    to be available.
  504.      */
  505.  
  506. BYTE
  507. PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error)
  508. {
  509.     WORD     i,j;
  510.     UBYTE    *Buffer;
  511.  
  512.         /* Run down the lines... */
  513.  
  514.     for(i = 0 ; i <= LastLine ; i++)
  515.     {
  516.             /* Grab the line. */
  517.  
  518.         Buffer = &Raster[i * RasterWidth];
  519.  
  520.         j = LastColumn;
  521.  
  522.             /* Strip trailing spaces. */
  523.  
  524.         while(j >= 0 && Buffer[j] == ' ')
  525.             j--;
  526.  
  527.             /* Blank line? */
  528.  
  529.         if(j >= 0)
  530.         {
  531.             if(!FWrite(File,Buffer,j + 1,1))
  532.             {
  533.                 *Error = IoErr();
  534.  
  535.                 return(FALSE);
  536.             }
  537.         }
  538.  
  539.             /* Is printing to be aborted? */
  540.  
  541.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  542.         {
  543.             *Error = 0;
  544.  
  545.             return(FALSE);
  546.         }
  547.  
  548.             /* Add line terminator. */
  549.  
  550.         if(!FWrite(File,"\n",1,1))
  551.         {
  552.             *Error = IoErr();
  553.  
  554.             return(FALSE);
  555.         }
  556.  
  557.             /* Is printing to be aborted? */
  558.  
  559.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  560.         {
  561.             *Error = 0;
  562.  
  563.             return(FALSE);
  564.         }
  565.     }
  566.  
  567.     return(TRUE);
  568. }
  569.  
  570.     /* PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error):
  571.      *
  572.      *    Print the contents of the clipboard.
  573.      */
  574.  
  575. BYTE
  576. PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error)
  577. {
  578.     LONG ClipError;
  579.  
  580.         /* Are we currently reading input from the
  581.          * clipboard? If so, close it.
  582.          */
  583.  
  584.     if(ClipInput)
  585.     {
  586.         CloseClip();
  587.  
  588.         ClipInput = ClipXerox = FALSE;
  589.     }
  590.  
  591.         /* Open the clipboard for reading. */
  592.  
  593.     if(ClipError = OpenClip(Config -> ClipConfig -> ClipboardUnit))
  594.     {
  595.         *Error = ERROR_OBJECT_NOT_FOUND;
  596.  
  597.         return(FALSE);
  598.     }
  599.     else
  600.     {
  601.         UBYTE    InputBuffer[257];
  602.         WORD    Len;
  603.  
  604.             /* Read clipboard contents. */
  605.  
  606.         while((Len = GetClip(InputBuffer,256,TRUE)) > 0)
  607.         {
  608.                 /* Are we to stop printing? */
  609.  
  610.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  611.             {
  612.                 *Error = 0;
  613.  
  614.                 return(FALSE);
  615.             }
  616.             else
  617.             {
  618.                 if(!FWrite(File,InputBuffer,Len,1))
  619.                 {
  620.                     *Error = IoErr();
  621.  
  622.                     return(FALSE);
  623.                 }
  624.             }
  625.         }
  626.  
  627.         if(Len < 0)
  628.         {
  629.             if(SysReqHandler(ReqWindow,NULL,FALSE) == -2)
  630.             {
  631.                 if(FPrintf(File,"\n") < 1)
  632.                     *Error = IoErr();
  633.  
  634.                 return(FALSE);
  635.             }
  636.         }
  637.  
  638.         CloseClip();
  639.     }
  640.  
  641.     return(TRUE);
  642. }
  643.  
  644.     /* PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error):
  645.      *
  646.      *    Print the contents of the text buffer.
  647.      */
  648.  
  649. BYTE
  650. PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error)
  651. {
  652.     BYTE Continue = TRUE;
  653.     LONG i,Len;
  654.  
  655.     ObtainSemaphore(BufferSemaphore);
  656.  
  657.     if(BufferLines)
  658.     {
  659.         for(i = 0 ; i < Lines ; i++)
  660.         {
  661.             Len = BufferLines[i][-1];
  662.  
  663.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  664.             {
  665.                 *Error = 0;
  666.  
  667.                 Continue = FALSE;
  668.  
  669.                 break;
  670.             }
  671.  
  672.             if(Len)
  673.             {
  674.                 if(FWrite(File,BufferLines[i],Len,1) != 1)
  675.                 {
  676.                     *Error = IoErr();
  677.  
  678.                     Continue = FALSE;
  679.  
  680.                     break;
  681.                 }
  682.             }
  683.  
  684.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  685.             {
  686.                 *Error = 0;
  687.  
  688.                 Continue = FALSE;
  689.  
  690.                 break;
  691.             }
  692.  
  693.             if(FPrintf(File,"\n") < 1)
  694.             {
  695.                 *Error = IoErr();
  696.  
  697.                 Continue = FALSE;
  698.  
  699.                 break;
  700.             }
  701.         }
  702.     }
  703.     else
  704.         Continue = FALSE;
  705.  
  706.     ReleaseSemaphore(BufferSemaphore);
  707.  
  708.     return(Continue);
  709. }
  710.  
  711.     /* PrintSomething(BYTE Source):
  712.      *
  713.      *    Print the screen or the current contents of the clipboard.
  714.      */
  715.  
  716. VOID
  717. PrintSomething(BYTE Source)
  718. {
  719.     struct Window        *ReqWindow;
  720.     struct EasyStruct     Easy;
  721.     LONG             Error = 0;
  722.  
  723.         /* Fill in the easy requester structure. */
  724.  
  725.     Easy . es_StructSize    = sizeof(struct EasyStruct);
  726.     Easy . es_Flags        = NULL;
  727.     Easy . es_Title        = (STRPTR)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  728.     Easy . es_GadgetFormat    = (STRPTR)LocaleString(MSG_PRINT_STOP_TXT);
  729.  
  730.     if(Source == PRINT_CLIP)
  731.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_CLIP_TXT);
  732.     else
  733.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_SCREEN_TXT);
  734.  
  735.         /* The requester is to be displayed while printing. */
  736.  
  737.     if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  738.     {
  739.         BPTR SomeFile;
  740.  
  741.             /* Add header information if printer channel is already open. */
  742.  
  743.         if(PrinterCapture)
  744.         {
  745.             if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT)) < 1)
  746.             {
  747.                 FreeSysRequest(ReqWindow);
  748.  
  749.                 ReqWindow = NULL;
  750.  
  751.                 Error = IoErr();
  752.             }
  753.             else
  754.                 SomeFile = PrinterCapture;
  755.         }
  756.         else
  757.         {
  758.                 /* Open printer channel. */
  759.  
  760.             if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  761.             {
  762.                 FreeSysRequest(ReqWindow);
  763.  
  764.                 ReqWindow = NULL;
  765.  
  766.                 Error = IoErr();
  767.             }
  768.         }
  769.  
  770.             /* Everything fine so far? */
  771.  
  772.         if(!Error)
  773.         {
  774.             BYTE Stopped = FALSE;
  775.  
  776.                 /* Are we to print the screen? */
  777.  
  778.             if(Source == PRINT_SCREEN)
  779.                 Stopped = !PrintScreen(SomeFile,ReqWindow,&Error);
  780.             else
  781.                 Stopped = !PrintClip(SomeFile,ReqWindow,&Error);
  782.  
  783.                 /* Add a trailer if necessary. */
  784.  
  785.             if(PrinterCapture)
  786.             {
  787.                 if(!Error && !Stopped)
  788.                 {
  789.                     if(FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT)) < 1)
  790.                         Error = IoErr();
  791.                 }
  792.             }
  793.             else
  794.             {
  795.                     /* Close the printer stream. */
  796.  
  797.                 if(!Close(SomeFile))
  798.                     Error = IoErr();
  799.             }
  800.         }
  801.  
  802.             /* Release the system requster. */
  803.  
  804.         if(ReqWindow)
  805.             FreeSysRequest(ReqWindow);
  806.  
  807.             /* Display the error code if necessary. */
  808.  
  809.         if(Error)
  810.         {
  811.             STRPTR ErrorString;
  812.  
  813.             if(Fault(Error,"",SharedBuffer,256))
  814.                 ErrorString = SharedBuffer;
  815.             else
  816.                 ErrorString = "???";
  817.  
  818.             MyEasyRequest(Window,LocaleString(MSG_PRINT_ERROR_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error,ErrorString);
  819.         }
  820.     }
  821. }
  822.  
  823.     /* PrintRegion(WORD Top,WORD Bottom):
  824.      *
  825.      *    Print the contents of a screen region.
  826.      */
  827.  
  828. VOID
  829. PrintRegion(WORD Top,WORD Bottom)
  830. {
  831.     BPTR     SomeFile;
  832.     WORD     i,j;
  833.     UBYTE    *Buffer;
  834.  
  835.     if(PrinterCapture)
  836.     {
  837.         if(!FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT)))
  838.         {
  839.             MyEasyRequest(Window,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  840.  
  841.             return;
  842.         }
  843.  
  844.         SomeFile = PrinterCapture;
  845.     }
  846.     else
  847.     {
  848.         if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  849.         {
  850.             MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  851.  
  852.             return;
  853.         }
  854.     }
  855.  
  856.     for(i = Top ; i < Bottom ; i++)
  857.     {
  858.         Buffer = &Raster[i * RasterWidth];
  859.  
  860.         j = LastColumn;
  861.  
  862.         while(j >= 0 && Buffer[j] == ' ')
  863.             j--;
  864.  
  865.         if(j >= 0)
  866.         {
  867.             if(!FWrite(SomeFile,Buffer,j + 1,1))
  868.                 break;
  869.         }
  870.  
  871.         if(!FWrite(SomeFile,"\n",1,1))
  872.             break;
  873.     }
  874.  
  875.     if(PrinterCapture)
  876.         FPrintf(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT));
  877.     else
  878.         Close(SomeFile);
  879. }
  880.